package com.link2room.ironhide.controller.manager;

import com.link2room.common.dto.param.base.BaseL2rParamDto;
import com.link2room.common.dto.param.base.BaseParamDto;
import com.link2room.common.dto.result.base.BaseResultDto;
import com.link2room.common.dto.result.base.L2RGroupBaseInfoDto;
import com.link2room.common.jpa.result.QueryResult;

import com.link2room.ironhide.dto.param.manager.L2RGroupBaseInfoManagerParamDto;
import com.link2room.ironhide.dto.param.manager.L2RServicesParamDto;
import com.link2room.ironhide.dto.result.base.L2RGroupBrandDto;
import com.link2room.ironhide.dto.result.manager.L2RServiceDto;
import com.link2room.ironhide.facade.IGroupBrandFacadeService;
import com.link2room.ironhide.facade.IGroupFacadeService;
import com.link2room.ironhide.facade.IL2RServicesFacadeService;
import com.link2room.sideswipe.permissionResouces.annotation.L2RPermissionResources;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.link2room.ironhide.constant.PermissionConstant.*;

/**
 * Created by sss on 2016/10/11.
 */
@Api(tags = "集团信息管理")
@RestController
@RequestMapping("/manager/GroupInfo")
public class GroupInfoManagerController {
    @Resource
    private IGroupBrandFacadeService groupBrandFacadeService;
    @Resource
    private IL2RServicesFacadeService l2RServicesFacadeService;
    @Resource
    private IGroupFacadeService groupFacadeService;

    @ApiOperation(value = "获取集团基础信息",response = L2RGroupBaseInfoDto.class)
    @RequestMapping(value = "/Group",method = RequestMethod.GET)
    @L2RPermissionResources(value = groupInfo, name = "获取集团信息")
    public BaseResultDto getGroupInfo(
    ) throws Exception {
        BaseParamDto baseParamDto=new BaseParamDto();
        L2RGroupBaseInfoDto groupBaseInfoDto = groupFacadeService.getGroupBaseInfo(baseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(groupBaseInfoDto);
        return l2rRs;
    }

    @ApiOperation(value = "新建集团基础信息",response = L2RGroupBaseInfoDto.class)
    @RequestMapping(value = "/Group",method = RequestMethod.POST)
    @L2RPermissionResources(value = newGroupInfo, name = "新建集团信息")
    public BaseResultDto newGroupInfo(
    ) throws Exception {
        L2RGroupBaseInfoManagerParamDto baseParamDto=new L2RGroupBaseInfoManagerParamDto();
        L2RGroupBaseInfoDto groupBaseInfoDto = groupFacadeService.saveOrUpdateGroupBaseInfo(baseParamDto);
        BaseResultDto l2rRs=new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(groupBaseInfoDto);
        return l2rRs;
    }

    @ApiOperation(value = "获取集团品牌列表", response = L2RGroupBrandDto.class)
    @RequestMapping(value = "/GroupBrands", method = RequestMethod.GET)
    @L2RPermissionResources(value = groupBrands, name = "获取集团品牌列表")
    public BaseResultDto groupBrands() throws Exception {
        BaseL2rParamDto baseL2rParamDto = new BaseL2rParamDto();
        QueryResult<L2RGroupBrandDto> l2RGroupBrandResult = groupBrandFacadeService.listL2RGroupBrand(baseL2rParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setQueryResult(l2RGroupBrandResult);
        return l2rRs;
    }

    @ApiOperation(value = "获取集团服务设施列表", response = L2RServiceDto.class)
    @RequestMapping(value = "/GroupServices", method = RequestMethod.GET)
    @L2RPermissionResources(value = groupServices, name = "获取集团服务设施列表")
    public BaseResultDto groupServices() throws Exception {
        BaseL2rParamDto baseL2rParamDto = new BaseL2rParamDto();
        List<L2RServiceDto> l2RServiceDtos = l2RServicesFacadeService.listGroupServices(baseL2rParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        l2rRs.setResultInfo(l2RServiceDtos);
        return l2rRs;
    }

    @ApiOperation(value="保存集团服务设施")
    @RequestMapping(value = "/GroupServices", method = RequestMethod.POST)
    @L2RPermissionResources(value = newGroupServices, name = "保存集团服务设施")
    public BaseResultDto newGroupServices(
            @RequestBody L2RServicesParamDto l2RServicesParamDto
    ) throws Exception {
        l2RServicesFacadeService.saveOrUpdateGroupServices(l2RServicesParamDto);
        BaseResultDto l2rRs = new BaseResultDto();
        l2rRs.setResultCode(0);
        return l2rRs;
    }
}
